package com.edu.exam.enums.monitoring;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 合规评级枚举
 * 管理巡考和监控的合规性评价等级
 *
 * @author System
 * @version 1.0.0
 */
public enum ComplianceRating implements BaseEnum {

    EXCELLENT("EXCELLENT", "优秀", 1),
    GOOD("GOOD", "良好", 2),
    SATISFACTORY("SATISFACTORY", "合格", 3),
    NEEDS_IMPROVEMENT("NEEDS_IMPROVEMENT", "需要改进", 4),
    POOR("POOR", "不合格", 5);

    private final String code;
    private final String description;
    private final int order;

    ComplianceRating(String code, String description, int order) {
        this.code = code;
        this.description = description;
        this.order = order;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    public int getOrder() {
        return order;
    }

    /**
     * 根据编码查找枚举值
     *
     * @param code 业务编码
     * @return 对应的枚举值，null如果未找到
     */
    public static ComplianceRating fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            return SATISFACTORY; // 默认合格
        }

        for (ComplianceRating value : values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        return SATISFACTORY;
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值，默认合格如果未找到
     */
    public static ComplianceRating fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            return SATISFACTORY; // 默认合格
        }

        for (ComplianceRating value : values()) {
            if (value.getDescription().equals(description)) {
                return value;
            }
        }
        return SATISFACTORY;
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}